package com.spring.controller;

import com.spring.mapper.UserMapper;
import com.spring.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
public class UserController {

    @Autowired
    UserMapper userMapper;

    // 查询全部部门
    @GetMapping("/queryUserList")
    public List<User> queryUserList() {
        return userMapper.queryUserList();
    }

    // 根据id查询用户
    @GetMapping("/queryUserById/{id}")
    public User queryUserById(@PathVariable("id") Integer id) {
        return userMapper.queryUserById(id);
    }

    //    添加用户
    @GetMapping("/addUser")
    public String addUser() {
        userMapper.addUser(new User("阿毛", "34334"));
        return "add OK";
    }

    //    修改用户
    @GetMapping("/updateUser")
    public String updateUser() {
        userMapper.updateUser(new User(6, "小红", "490333"));
        return "udpate OK";
    }

    //    删除用户
    @GetMapping("/deleteUser")
    public String deleteUser() {
        userMapper.deleteUser(5);
        return "delete OK";
    }
}